import { getModelInfo } from '@ve/utils/getModelInfo'
import { webapp_ws_fun_log } from '@ve/utils/print/grwebapp'
export default function websocketTableData({ vm, action, done }) {
  let _componentId = action.extension.tableId.value[0]
  let _modelInfo = getModelInfo(vm, _componentId)
  let _selfRef = vm.vuiComponents && vm.vuiComponents[_modelInfo._id]
  console.log('_modelInfo', _modelInfo)
  _selfRef.self.$data.loading = false
  webapp_ws_fun_log()
  if (window.webapp_onmessage) {
    window.webapp_onmessage = (event) => {
      let message = JSON.parse(event.data)
      if (message.type == 'fun') {
        switch (message.fun) {
          case 'log':
            vm.$store.dispatch('diyPrint/setPrintLog', message)
            break
          case 'template':
            vm.$store.dispatch('diyPrint/setMonitorData', { modelInfoId: _modelInfo._id, message })
            console.log(message.TEMPLATES)
            _modelInfo.data.requestData.data = message.TEMPLATES
        }
      }
    }
    done()
  }
  // done()
}
